// pages/reserve/reserve.js
import {
    request,
} from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
import {
    getSetting,
    openSetting,
    showModal,
    showToast,
    getUserProfile,
    checkImgExists
} from "../../utils/asyncWx.js";
Page({

    /**
     * 页面的初始数据
     */
    data: {
       
        numList:["1~2人","3~4人","5~8人"],
        rst:{}

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const index=options.index;
        const page = getCurrentPages();
        const rst=page[page.length-2].data.myViewList[index];
        this.setData({
            rst
        });

    },

    handleReserve(options){
        const flag=options.currentTarget.dataset.value;
        wx.showModal({
            title: '提示',
            content: '是否要选择'+this.data.numList[flag]+"座位",
            success:(res)=>{
                if(res.confirm){
                    const resID=this.data.rst.resID;
                    request({
                        url:'queue/create',
                        method:"POST",
                        data:{
                            flag,resID
                        },
                        header: {
                            'content-type': 'application/x-www-form-urlencoded'
                          },
                    })
                    // wx.reLaunch({
                    //   url: '/pages/home/home',
                    // })
                    const page = getCurrentPages();
                    const rst = page[page.length - 3];
                    rst.setData({
                        hasReserved: true
                    })
                    wx.navigateBack({
                      delta: 2,
                    })
                }
                else{
                    return;
                }
            },
            fail:(err)=>{
                console.log(err);
            }
        })
        
        
    }

})